<?php
#基础函数
include_once('_path.php');

if (BENCHMARK) {
	require_once(_CONST_LOCAL_INCLUDE_PATH.'/Benchmark/Timer.php');
	$timer = new Benchmark_Timer();
	$timer->start();
}

#db
include_once(_CONST_LOCAL_INCLUDE_PATH."database.class.php");
$database = new Database($db_vars);

if ($db_slave_vars['hostname'] != '') {
	$slave = new Database($db_slave_vars);
} else {
	$slave =& $database;
}

#通用函数
include_once(_CONST_LOCAL_INCLUDE_PATH."common.php");

if (BENCHMARK) $timer->setMarker('init');

#用户信息
include_once(_CONST_LOCAL_INCLUDE_PATH."session.include.php");

if (BENCHMARK) $timer->setMarker('auth');

#load model
load_model(array("vote"));

#翻页
$page = trim($_GET['page']) + 0;
if ($page < 1) $page = 1;
$count = get_all_vote_count();
$total_page = ceil($count / 50);
if ($total_page < 1) $total_page = 1;
if ($page > $total_page) $page = $total_page;

#cache lite
include_once(_CONST_LOCAL_INCLUDE_PATH.'Cache/Lite.php');
include_once(_CONST_LOCAL_INCLUDE_PATH.'Cache/Lite/Output.php');

$cache = new Cache_Lite_Output();

#用于meta的keywords标签
$keywords = "";
#用于meta的Description标签
$description = "";
#用于mete的http-equiv标签
$referrer = "";
#用于meta的title标签
$title = "首页 - Votings";
#用于获取针对本页的css样式
$css = array();
#用于获取针对本页的js
$js = array("jquery.masonry.min", "jquery.infinitescroll.min");
#用于获取针对head的其他标签
$links = array();
#用于控制那个主菜单为
$o = "";

$ads = array();

$post_code =<<<HTML
HTML;

if (BENCHMARK) $timer->setMarker('proc');

//if ($user['loggedin'] < 1)
//	cache_header(900);

no_cache_header();

#header
include_once(_CONST_LOCAL_LAYOUT_PATH."_header.php");
?>
<script>
$(function(){
    //hide page
    $("#page-nav-real").hide();
	//IMAGE STYLE
	var $container = $('#container');
	$container.imagesLoaded( function() {
		$container.masonry({
			itemSelector : '.pin',
			isAnimated: 'true'
		});
	});
	//page loading
	$container.infinitescroll({
		navSelector  : '#page-nav',    // selector for the paged navigation 
		nextSelector : '#page-nav a',  // selector for the NEXT link (to page 2)
		itemSelector : '.pin',     // selector for all items you'll retrieve
		loading: {
			finishedMsgShow:'#page-nav-real',
			finishedMsg: 'No more pages to load.',
			img:'media/bg/loadajax.gif',
			msgText:'loading...'
		}
    },
      // trigger Masonry as a callback
      function( newElements ) {
        // hide new items while they are loading
        var $newElems = $( newElements ).css({ opacity: 0 });
        // ensure that images load before adding to masonry layout
        $newElems.imagesLoaded(function(){
          // show elems now they're ready
          $newElems.animate({ opacity: 1 });
          $container.masonry( 'appended', $newElems, true ); 
        });
      }
    );
});
</script>
 <div id="main">
	<div class="box box-header"><h1>投票</h1></div>
	<div id="container">
	<?php 
	$rs = get_all_vote($page);
	if(sizeof($rs)>0){
	foreach($rs as $h){
	?>
<div class="pin">
	<a href="<?php echo _CONST_WEB_URL . 'vote.php?id=' . $h['id']?>"><img src="<?php echo _CONST_PIC_URL . 'vote/' . $h['user_id'] . '/1_' .$h['images']?>" /></a>
	<div class="votings-info">
		<div class="votings-user"><span class="name"><?php echo $h['name']?></span><img src="<?php echo iif(!empty($h['avatar']), _CONST_PIC_URL . 'avatar/' . $h['user_id'] . '/1_' . $h['avatar'], _CONST_IMG_URL . 'avatar/1.jpg')?>" alt="<?php echo $h['name']?>" /></div>
		<div class="votings-data"><span class="votings-down"><?php echo $h['sub']?></span><span class="votings-up"><?php echo $h['add']?></span></div>
	</div>
</div>
	<?php 
	}
	}
	?>	
	</div>
	<div id="page-nav"><a href="ajax/page.php?page=<?php echo ($page-1)*5+2?>"></a></div>
	<div class="jogger" id="page-nav-real">
	<?php 
	pagination($page, 50, $count, "?page=%s%");
	?>
	</div>
</div>
<!--main end-->
<?php
//footer
include_once (_CONST_LOCAL_LAYOUT_PATH."_footer.php");

if (BENCHMARK) $timer->setMarker('page');

if (BENCHMARK) {
	echo "<!-- init: ".$timer->timeElapsed('Start', 'init')." -->\n";
	echo "<!-- auth: ".$timer->timeElapsed('init', 'auth')." -->\n";
	echo "<!-- proc: ".$timer->timeElapsed('auth', 'proc')." -->\n";
	echo "<!-- page: ".$timer->timeElapsed('proc', 'page')." -->\n";
	echo "<!-- total: ".$timer->timeElapsed('Start', 'Stop')." -->\n";
}

?>
